package com.cata.mall.portal.controller;

import com.cata.mall.common.api.CommonResult;
import com.cata.mall.model.CmsSubject;
import com.cata.mall.model.PmsProduct;
import com.cata.mall.model.PmsProductCategory;
import com.cata.mall.portal.domain.HomeContentResult;
import com.cata.mall.portal.service.HomeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @作者: Tao
 * @日期: 2025/10/21
 * @时间: 09:45
 * @描述: 首页内容管理Controller<pre>
 */
@RestController
@Api(tags = "HomeController")
@Tag(name = "HomeController", description = "首页内容管理")
@RequestMapping("/home")
public class HomeController {
    @Autowired
    private HomeService homeService;

    /**
     * 首页内容信息展示
     *
     * @return 首页内容结果封装对象
     */
    @ApiOperation("首页内容信息展示")
    @GetMapping(value = "/content")
    public CommonResult<HomeContentResult> content() {
        HomeContentResult contentResult = homeService.content();
        return CommonResult.success(contentResult);
    }

    /**
     * 分页获取推荐商品
     *
     * @param pageSize 每页数量，默认为4
     * @param pageNum  页码，默认为1
     * @return 推荐商品列表
     */
    @ApiOperation("分页获取推荐商品")
    @GetMapping(value = "/recommendProductList")
    public CommonResult<List<PmsProduct>> recommendProductList(@RequestParam(value = "pageSize", defaultValue = "4") Integer pageSize,
                                                               @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        List<PmsProduct> productList = homeService.recommendProductList(pageSize, pageNum);
        return CommonResult.success(productList);
    }

    /**
     * 获取首页商品分类
     *
     * @param parentId 父级分类ID
     * @return 商品分类列表
     */
    @ApiOperation("获取首页商品分类")
    @GetMapping(value = "/productCateList/{parentId}")
    public CommonResult<List<PmsProductCategory>> getProductCateList(@PathVariable Long parentId) {
        List<PmsProductCategory> productCategoryList = homeService.getProductCateList(parentId);
        return CommonResult.success(productCategoryList);
    }

    /**
     * 根据分类分页获取专题
     *
     * @param cateId   专题分类ID（可选）
     * @param pageSize 每页数量，默认为4
     * @param pageNum  页码，默认为1
     * @return 专题列表
     */
    @ApiOperation("根据分类分页获取专题")
    @GetMapping(value = "/subjectList")
    public CommonResult<List<CmsSubject>> getSubjectList(@RequestParam(required = false) Long cateId,
                                                         @RequestParam(value = "pageSize", defaultValue = "4") Integer pageSize,
                                                         @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        List<CmsSubject> subjectList = homeService.getSubjectList(cateId, pageSize, pageNum);
        return CommonResult.success(subjectList);
    }

    /**
     * 分页获取人气推荐商品
     *
     * @param pageNum  页码，默认为1
     * @param pageSize 每页数量，默认为6
     * @return 人气推荐商品列表
     */
    @ApiOperation("分页获取人气推荐商品")
    @GetMapping(value = "/hotProductList")
    public CommonResult<List<PmsProduct>> hotProductList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                         @RequestParam(value = "pageSize", defaultValue = "6") Integer pageSize) {
        List<PmsProduct> productList = homeService.hotProductList(pageNum, pageSize);
        return CommonResult.success(productList);
    }

    /**
     * 分页获取新品推荐商品
     *
     * @param pageNum  页码，默认为1
     * @param pageSize 每页数量，默认为6
     * @return 新品推荐商品列表
     */
    @ApiOperation("分页获取新品推荐商品")
    @GetMapping(value = "/newProductList")
    public CommonResult<List<PmsProduct>> newProductList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                         @RequestParam(value = "pageSize", defaultValue = "6") Integer pageSize) {
        List<PmsProduct> productList = homeService.newProductList(pageNum, pageSize);
        return CommonResult.success(productList);
    }

}
